2016年2月9日火曜日

httpアクセスの問題

「App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.」
というエラーに悩まされました。

以下のサイトが参考になりました。
http://mushikago.com/i/?p=6150

httpsではない、httpのURLを見に行くと、セキュリティ的に怒られる様子。
困った。

上記のサイトから、Xcodeのバージョンが上がり、記載が変わっていました。
「App Transport Security Settings」を「Allow Arbitrary Loads」に設定することで解決しました。

Xcode7.2にて。

アプリを作っていて、なぜか画面の上下に黒い部分が

アプリを作っていて、なぜか画面の上下に黒い部分ができました。

画面サイズが小さい。

info.plistの
「Launch screen interface file base name」の部分を消したことが原因でした。

コードでレイアウトして、storyboardとかinterface builderを使わないので、
これもいらない気がして削除して、ちょっとはまりました。

あまり他に似たような人はいないかと思いますが、一応。

このpropertyを復活させて、valueを「LaunchScreen」にしたら、無事復活。

よかった。

2016年1月13日水曜日

SwiftでのStringの最後の文字にアクセスするメモ

SwiftでのStringに関して、

Use the startIndex property to access the position of the first Character of a String. The endIndex property is the position after the last character in a String.
と、以下に書いてありました。
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html

要するに、Stringの最後の文字にアクセスしようとしたら、endIndexというプロパティではアクセスできず、predecessor()というメソッドでアクセスせねばならぬとのこと。
なるほど。。

let lastChar = str[str.endIndex.predecessor()]

という感じで。

最後の文字を削除したければ

str.removeAtIndex(str.endIndex.predecessor())
でOK。

Stringに関するメモでした。