NSSearchPathDirectory use of unresolved identifier - macos

In my app I want to save some information for the user somewhere. I picked the Application Support Directory, which I am trying to get like so:
let savePath = NSSearchPathForDirectoriesInDomains(ApplicationSupportDirectory, UserDomainMask, true)
Im getting a compile error in XCode saying "Use of unresolved identifier", even though the function is requesting a NSSearchPathDirectory type, which according to Apple's documentation clearly exists:
enum NSSearchPathDirectory : UInt {
case ApplicationDirectory
...
case ApplicationSupportDirectory
...
}
The same problem occurs with 'UserDomainMask'
Is this a bug or am I missing something? (Also, I would prefer not to use a workaround like substituting an integer literal...)

The correct statement is:
let savePath = NSSearchPathForDirectoriesInDomains(.ApplicationSupportDirectory, .UserDomainMask, true)
println("savePath: \(savePath)")
output:
savePath: [/Users/zaph/Library/Developer/CoreSimulator/Devices/24F94BD2-9DD7-4BC6-AA66-128AC1E7555F/data/Containers/Data/Application/9FFA8987-A36B-4A4D-A607-1BC220ADBBF2/Library/Application Support]
A leading "." is needed for the enumeration values.

Related

'RedisCluster' has no member named 'get_shards_pool'

I am trying to build DeathStarBench (https://github.com/delimitrou/DeathStarBench), however, I am getting the following error:
In file included from /social-network-microservices/src/HomeTimelineService/HomeTimelineService.cpp:15:0:
/social-network-microservices/src/HomeTimelineService/HomeTimelineHandler.h: In member function 'virtual void social_network::HomeTimelineHandler::WriteHomeTimeline(int64_t, int64_t, int64_t, int64_t, const std::vector&, const std::mapstd::__cxx11::basic_string<char, std::__cxx11::basic_string >&)':
/social-network-microservices/src/HomeTimelineService/HomeTimelineHandler.h:129:55: error: 'class sw::redis::RedisCluster' has no member named 'get_shards_pool'
auto *shards_pool = _redis_cluster_client_pool->get_shards_pool();
I don't know anything about Redis. However, I googled the error message and couldn't find anything related to this. Any suggestions on what might be the problem?

Errors with find_if() & mem_fun1()

I have code that worked well in Visual C++ 6.0. Now I need to get it working in VS 2017. I have some error messages when I compile, and I'm really not sure how to fix it. Here's the code:
class CTagDB : public CObject
{
...
bool SameTag (const CTagDB *TagDB) { return TagDB && *this == *TagDB; }
...
}
class CTagsDB : public CObject
{
...
std::vector<CTagDB*> m_Tags;
...
}
bool CTagsDB::IsDup(const CTagDB *TagDB) const
{
return std::find_if(m_Tags.begin(), m_Tags.end(),
std::bind2nd(std::mem_fun1(CTagDB::SameTag),
TagDB)) != m_Tags.end();
}
For this code I get the following errors:
error C2039: 'mem_fun1': is not a member of 'std' C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include\map(16):
note: see declaration of 'std'
error C3867: 'CTagDB::SameTag': non-standard syntax; use '&' to create a pointer to member
error C3861: 'mem_fun1': identifier not found
error C2672: 'std::find_if': no matching overloaded function found
error C2780: '_InIt std::find_if(_InIt,_InIt,_Pr)': expects 3 arguments - 2 provided
Seeing the methods begin() & end(), I suspect that there is a problem with the way the vectors are being used, because originally the code was written without iterators. But this fragment of code is so clever as to be very difficult to decipher, let alone maintain (by me).
Can anyone help me figure out what is going on here and how to fix it?

Vala error "unknown type name" using enum from camel

I am writing this code in Vala, using Camel
using Camel;
[...]
MimeParser par = new MimeParser();
[...]
par.push_state( MimeParserState.MULTIPART, boundary );
I downloaded the camel-1.2.vapi from github vala-girs (this link), put it in a vapi subdirectory and compiled with
valac --vapidir=vapi --includedir=/usr/include/evolution-data-server/camel --pkg camel-1.2 --pkg posix --target-glib=2.32 -o prog prog.vala -X -lcamel-1.2
Compiling I get this error:
error: unknown type name "CamelMimeParserState"
const gchar* camel_mime_parser_state_to_string (CamelMimeParserState self);
Looking the C output code I see that the CamelMimeParserState type is used several times but it is never defined. It should be a simple enum because the camel-1.2.vapi file says:
[CCode (cheader_filename = "camel/camel.h", cprefix = "CAMEL_MIME_PARSER_STATE_", has_type_id = false)]
public enum MimeParserState {
INITIAL,
PRE_FROM,
FROM,
HEADER,
BODY,
MULTIPART,
MESSAGE,
PART,
END,
EOF,
PRE_FROM_END,
FROM_END,
HEADER_END,
BODY_END,
MULTIPART_END,
MESSAGE_END
}
So why doesn't the C output code simply use an enum as the vapi file says (described by cprefix CAMEL_MIME_PARSER_STATE_)?
Is there an error in the .vapi file?
I found the solution. The vapi file is wrong because the cname field is missing. Changing the vapi file adding this cname="camel_mime_parser_state_t":
[CCode (cheader_filename = "camel/camel.h", cname="camel_mime_parser_state_t", cprefix = "CAMEL_MIME_PARSER_STATE_", has_type_id = false)]
public enum MimeParserState {
INITIAL,
[...]
works correctly.

Xcode beta 7 - Do-While loop SWIFT Error

The following code gives the error
Expected 'while' in 'do-while' loop
if let path = NSBundle.mainBundle().pathForResource("Chapters", ofType: "txt"){
do {
let stringFromFile = try String(contentsOfFile:path, encoding: NSUTF8StringEncoding)
var chapters: [String] = stringFromFile.componentsSeparatedByString("#")
chapters.removeAtIndex(0)
} catch {
print((error))
}
}
it was working fine before, but now it's giving me an error. Does anyone know why?
That code works for me as-is in the Playground with the appropriate Chapters.txt file in the Resources folder; XCode 7.1 Build 7B60. Did you try Shift-Command-K for a Clean Build?
Something does not seem right with your error message. With Swift 2.0, there are no more do-while loops. They have been replaced by repeat-while loops instead. As your code snippet shows, do has been repurposed for do-try-catch error handling.

Pebble C TupletCString compile error

I have an issue compiling my pebble watchapp. I am trying to send strings to the Pebbl eJS script on the phone lihe this:
Tuplet password_tuple = TupletCString(PASSWORD_KEY, password_str);
Tuplet email_tuple = TupletCString(EMAIL_KEY, email_str);
The compiler error is: (they both error out like this, this is just one of the lines of output below)
./src/app_test.c:84:25: error: the address of 'email_str' will always evaluate as 'true' [-Werror=address]
email_str and password_str are defined at the top of the program, like this:
static char email_str[30];
static char password_str[30];
#define PASSWORD_PKEY (int32_t)21
#define EMAIL_PKEY (int32_t)20
Does anyone notice anything wrong with this?
#ismail-badawi answer is very correct.
Pebble now recommends that you use dict_write_cstring.
dict_write_cstring(&iter, SOME_STRING_KEY, string);
Well it's certainly not obvious, but it turns out it's because TupletCString is a macro, and it'll expand to an expression that contains email_str ? strlen(email_str) + 1 : 0 as a subexpression, and this is what causes the error, because email_str can't be null and so the comparison isn't doing anything.
I found this thread on the Pebble forums with an explanation. The suggested fix is to define your own macro that doesn't have a conditional, e.g.
#define MyTupletCString(_key, _cstring) \
((const Tuplet) { .type = TUPLE_CSTRING, .key = _key, .cstring = { .data = _cstring, .length = strlen(_cstring) + 1 }})

Resources